#!/bin/bash
exe=/usr/local/mysql/mysql/bin
echo 'export PATH=$PATH:/usr/local/mysql/mysql/bin' >> /etc/profile
source /etc/profile
$exe/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql
$exe/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/mysql/data &> /dev/null
systemctl daemon-reload
systemctl start mysqld
systemctl enable mysqld
pass=$(grep 'password' /usr/local/mysql/mysql/master.err|awk '{print $NF}')
new_pass=123456
$exe/mysqladmin -uroot password $new_pass  -p$pass
ln -s /lib64/libncurses.so.6 /lib64/libncurses.so.5
ln -s /lib64/libtinfo.so.6 /lib64/libtinfo.so.5
$exe/mysql -uroot -p$new_pass <<EOF
create user slave@'%' identified by '123456';
grant replication slave,replication client on *.* to slave@'%';
flush privileges;
EOF
$exe/mysqldump -uroot -p$new_pass -A --master-data=2 -F --single-transaction -R -E -triggers | gzip > /opt/full.sql.gz
scp /opt/full.sql.gz root@192.168.88.130:/opt
$exe/mysql -uroot -p$new_pass -e "flush tables with read lock;"
